package com.web.music.portal.mvc;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import com.web.music.interfaces.ArtistService;
import com.web.music.interfaces.SecurityController;
import com.web.music.model.Artist;

public class ListAllArtistController implements Controller {

	private ArtistService artistService;
	private SecurityController securityController;	
	
	public ArtistService getArtistService() {
		return artistService;
	}

	public void setArtistService(ArtistService artistService) {
		this.artistService = artistService;
	}

	public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) 
	throws Exception 
	{
		String searchMode = request.getParameter("smode");
		if (searchMode==null){
			searchMode = "all";
		}
		List<Artist> singers = artistService.findAll("singer");
		List<Artist> bands = artistService.findAll("band");
		
		securityController.updateSecurityStatus(request, singers);
		securityController.updateSecurityStatus(request, bands);
		
		ModelAndView mv= new ModelAndView("artist_listall");
		if (searchMode.equals("all")){
			mv.addObject("singer_list", singers);
			mv.addObject("band_list", bands);
		}
		else if (searchMode.equals("singer")){
			mv.addObject("singer_list", singers);
		}
		else if (searchMode.equals("band")){
			mv.addObject("band_list", bands);
		}
		return mv;
	}
	public SecurityController getSecurityController() {
		return securityController;
	}

	public void setSecurityController(
			SecurityController securityController) {
		this.securityController = securityController;
	}	
}